
import i18n from '@/locales/index' 
import { formatTime } from '@/utils'
const { t } = i18n.global;
const validtWorkNo = async (_rule, value) => {
  if (!value) {
    return Promise.reject(t('sysManage.enterJobNo'));
  }
  if (/^[0-9]{1,8}$/.test(value)) {
    return Promise.resolve();
  } else {
    return Promise.reject(t('sysManage.jobNoMax8'));
  }
}

const validtPhone = async (_rule, value) => {
  if (!value) {
    return Promise.resolve();
  } else {
    if (value.length !== 11) {
      return Promise.reject(t('sysManage.ruleTruePhone'));
    } else {
      return Promise.resolve();
    }
  }
}

export const staffRule = {
  clientId: [{
    required: true,
    message: t('sysManage.selectClient'),
    trigger: 'change',
  }],
  status: [{
    required: true,
    message: t('common.pleaseSelectStartState'),
    trigger: 'change',
  }],
  staffNo: [{
    required: true,
    trigger: 'change',
    validator: validtWorkNo
  }],
  nickName: [{
    required: true,
    message: t('sysManage.enterName'),
    trigger: 'change',
  }],
  // deptId: [{
  //   required: true,
  //   message: '请选择部门t('basicData.group')',
  //   trigger: 'change',
  // }],
  postStatus: [{
    required: true,
    message: t('sysManage.pleaseSelectPositionStatus'),
    trigger: 'change',
  }],
  phonenumber: [{
    trigger: 'change',
    validator: validtPhone
  }]
}

export const normalColumns = [
  {
    title: t('common.sequenceNo'), dataIndex: 'index', key: 'index', align: 'center', width: 60,
    customRender: ({ index }) => {
      return index + 1
    },
  },
  { title: t('basicData.name'), dataIndex: 'nickName', key: 'nickName', align: 'center', width: 100 },
  { title: t('basicData.jobNo'), dataIndex: 'staffNo', key: 'staffNo', align: 'center', width: 150 },
  // { title: '卡号', dataIndex: 'cardNo', key: 'cardNo', align: 'center', width: 110 },
  { title: t('deviceManage.waterLine'), dataIndex: 'lineList', key: 'lineList', align: 'center', width: 150,
    customRender: ({ text }) => {
      return text?.length ? text.map(i => i.lineNo).join() : ''
    } 
  }, 
  { title: t('basicData.section'), dataIndex: 'sectionName', key: 'sectionName', align: 'center', width: 150,
    customRender: ({ record }) => {
      return record.lineList?.length ? record.lineList.map(i => i.sectionName).filter(i=> i).join() : ''
    } 
  },
  { title: t('sysManage.depart'), dataIndex: 'dept', key: 'dept', align: 'center', width: 130 },
  // { title: '工种', dataIndex: 'profession', key: 'profession', align: 'center', width: 90 },
  // { title: '岗位状态', dataIndex: 'postStatus', key: 'postStatus', align: 'center', width: 80 },
  { title: t('sysManage.phoneNo'), dataIndex: 'phonenumber', key: 'phonenumber', align: 'center', width: 110 },
  { title: t('sysManage.role'), dataIndex: 'roles', key: 'roles', align: 'center', width: 90 },
  {
    title: t('common.createTime'), dataIndex: 'createTime', key: 'createTime', align: 'center', width: 170, timeType: 'time',
    customRender: ({ text }) => {
      return formatTime(text, 'YYYY-MM-DD HH:mm:ss')
    }
  },
  {
    title: t('common.updateTime'), dataIndex: 'updateTime', key: 'updateTime', align: 'center', width: 170, timeType: 'time',
    customRender: ({ text }) => {
      return formatTime(text, 'YYYY-MM-DD HH:mm:ss')
    }
  },
  { title: t('common.startState'), dataIndex: 'status', key: 'status', align: 'center', width: 100 },
  { title: t('common.operate'), dataIndex: 'operate', key: 'operate', align: 'center', width: 260, fixed: 'right' },
]
export const localColumns = [
  {
    title: t('common.sequenceNo'), dataIndex: 'index', key: 'index', align: 'center', width: 60,
    customRender: ({ index }) => {
      return index + 1
    },
  },
  { title: t('basicData.name'), dataIndex: 'nickName', key: 'nickName', align: 'center', width: 100 },
  { title: t('basicData.jobNo'), dataIndex: 'staffNo', key: 'staffNo', align: 'center', width: 150 },
  // { title: '卡号', dataIndex: 'cardNo', key: 'cardNo', align: 'center', width: 110 },
  { title: t('deviceManage.waterLine'), dataIndex: 'lineList', key: 'lineList', align: 'center', width: 150, 
    customRender: ({ text }) => {
      return text?.length ? text.map(i => i.lineNo).join() : ''
    } 
  }, 
  { title: t('basicData.section'), dataIndex: 'sectionName', key: 'sectionName', align: 'center', width: 150,
    customRender: ({ record }) => {
      return record.lineList?.length ? record.lineList.map(i => i.sectionName).filter(i=> i).join() : ''
    } 
  },
  { title: t('sysManage.depart'), dataIndex: 'dept', key: 'dept', align: 'center', width: 130 },
  // { title: '工种', dataIndex: 'profession', key: 'profession', align: 'center', width: 90 },
  // { title: '岗位状态', dataIndex: 'postStatus', key: 'postStatus', align: 'center', width: 80 },
  { title: t('sysManage.phoneNo'), dataIndex: 'phonenumber', key: 'phonenumber', align: 'center', width: 110 },
  { title: t('sysManage.role'), dataIndex: 'roles', key: 'roles', align: 'center', width: 90 },
  {
    title: t('common.createTime'), dataIndex: 'createTime', key: 'createTime', align: 'center', width: 170, timeType: 'time',
    customRender: ({ text }) => {
      return formatTime(text, 'YYYY-MM-DD HH:mm:ss')
    }
  },
  {
    title: t('common.updateTime'), dataIndex: 'updateTime', key: 'updateTime', align: 'center', width: 170, timeType: 'time',
    customRender: ({ text }) => {
      return formatTime(text, 'YYYY-MM-DD HH:mm:ss')
    }
  },
  { title: t('common.startState'), dataIndex: 'status', key: 'status', align: 'center', width: 100 }
]